package l_chain_of_responsibility.a_origin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by wug on 2016/8/9 0009.
 */
public class MainTest {
    public static void main(String[] args) {
        MainTest mainTest = new MainTest();

        String str = "/smile<script>while(true){alert(\"ok\")}</script>第三十一届夏季奥林匹克运动会AV女优又称里约奥运会绿茶婊";
        System.out.println(str);

        str = mainTest.faceTran(str);
        System.out.println(str);

        str = mainTest.htmlTran(str);
        System.out.println(str);

        str = mainTest.sensitiveTran(str);
        System.out.println(str);
    }

    private String faceTran(String str) {
        Map<String, String> faceMap = getFacePackge();
        Set<Map.Entry<String, String>> ertrys = faceMap.entrySet();
        for (Map.Entry<String, String> entry : ertrys) {
            str = str.replaceAll("/"+entry.getKey(), entry.getValue());
        }
        return str;
    }

    private String htmlTran(String str) {
        str = str.replaceAll("<", "[");
        str = str.replaceAll(">", "]");
        return str;
    }

    private String sensitiveTran(String str) {
        List<String> sensitiveList = getSencitiveDict();
        for (String sensitive : sensitiveList) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < sensitive.length(); i++) {
                sb.append("*");
            }

            str = str.replace(sensitive, sb);
        }
        return str;
    }

    private Map<String, String> getFacePackge() {
        Map<String, String> map = new HashMap<>();
        map.put("smile","^_^");
        map.put("cry","V^V");
        return map;
    }

    private List<String> getSencitiveDict() {
        List<String> list = new ArrayList<>();
        list.add("AV女优");
        list.add("绿茶婊");
        list.add("日了狗");
        return list;
    }
}
